package com.bckj.fastboot.core.lang.model;

import com.bckj.fastboot.core.lang.constant.HttpConstants;

public record ApiResponse<T> (int code, String msg, T data) {

    public static <T> ApiResponse<T> ok() {
        return restResult(null, HttpConstants.SUCCESS, null);
    }

    public static <T> ApiResponse<T> ok(T data) {
        return restResult(data, HttpConstants.SUCCESS, null);
    }

    public static <T> ApiResponse<T> ok(T data, String msg) {
        return restResult(data, HttpConstants.SUCCESS, msg);
    }

    public static <T> ApiResponse<T> failed() {
        return restResult(null, HttpConstants.ERROR, null);
    }

    public static <T> ApiResponse<T> failed(String msg) {
        return restResult(null, HttpConstants.ERROR, msg);
    }

    public static <T> ApiResponse<T> failed(T data) {
        return restResult(data, HttpConstants.ERROR, null);
    }

    public static <T> ApiResponse<T> failed(T data, String msg) {
        return restResult(data, HttpConstants.ERROR, msg);
    }

    public static <T> ApiResponse<T> restResult(T data, int code, String msg) {
        return new ApiResponse<>(code, msg, data);
    }

}